﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <script src="/js/header.js"></script>
    <script src="/js/framebox.js"></script>
    <title>秒付宝-卡管系统</title>
</head>
<body>
    <!--fram-wrap start-->
    <div class="fram-wrap clearfix">
        <!--fram-aside start-->
        <aside class="fram-aside">
            <h3 class="fram-logo"><span></span><span>卡管</span></h3>
            <div id="side_menu" class="side-menu">
            </div>
            <script type="text/x-dot-template" id="menuTemplate">
                <ul id="side_ul" class="side-ul">
                    {{? it.data && it.data.length>0}}
                    {{~it.data :value:index}}
                    <li class="fir-li">
                        <a pageid="a{{= value.id }}"><i class="iconfont icon-briefcase"></i><font>{{= value.name }}</font></a>
                        {{? value.childMenus && value.childMenus.length>0}}
                        <ul>
                            {{for(var i=0; i<value.childMenus.length; i++){ }}
                            <li><a pageid="a{{= value.id }}_{{= value.childMenus[i].id }}" targetpage="{{= value.childMenus[i].url }}">{{= value.childMenus[i].name }}</a></li>
                            {{}}}
                        </ul>
                        {{?}}
                    </li>
                    {{~}}
                    {{??}}
                    {{?}}
                </ul>
            </script>
        </aside>
        <!--fram-aside end-->
        <!--fram-article start-->
        <article class="fram-article open">
            <!--ftop-wrap start-->
            <header class="ftop-wrap clearfix case">
                <dl class="ftop-dl">
                    <dt class="ftop-dt"><a id="menu_pack" href="javascript:void(0)"><i class="iconfont icon-menu icon-pack"></i></a></dt>
                    <dd class="ftop-dd">
                        <a href="javascript:void(0)"><i class="iconfont icon-user"></i><span id="username"></span></a>
                        <a href="javascript:void(0)" class="update-password" data-modal="/view/user/editpassword.html" data-title="修改密码" data-width="430" data-height="260"><i class="glyphicon glyphicon-edit"></i></a>
                        <a href="#" id="logout"><i class="iconfont icon-off"></i></a>
                    </dd>
                </dl>
            </header>
            <!--ftop-wrap end-->
            <!--fscr-menu start-->
            <section id="fscr_menu" class="fscr-menu clearfix">
                <div class="fscr-act">
                    <a id="clearNav" href="javascript:void(0)"><i class="iconfont icon-clear"></i></a>
                    <a id="refreshbox" href="javascript:void(0)"><i class="iconfont icon-repeat"></i></a>
                </div>
                <div class="fscr-nav" id="fscr_nav">
                    <ul id="fscr_ul">
                        <li class="menuon" pageid="a1"><a>首页</a></li>
                    </ul>
                    <div class="fscr-arrow">
                        <a id="left_scroll" href="javascript:void(0)"><i class="iconfont icon-menu-left"></i></a>
                        <a id="right_scroll" href="javascript:void(0)"><i class="iconfont icon-menu-right"></i></a>
                    </div>
                </div>
            </section>
            <!--fscr-menu end-->
            <!--iframe-wrap start-->
            <section id="iframewrap" class="iframe-wrap">
                <iframe class="show" width="100%" pageid="a1" frameborder="0" scrolling-x="no" id="ifmamedefault" src="home.html"></iframe>
            </section>
            <!--iframe-wrap end-->
        </article>
        <!--fram-article end-->
    </div>
    <!--fram-wrap start-->

    <script type="text/javascript">
        $(function () {

            var RowScroll = new SellerScroll({
                container: "fscr_menu",
                con_nner: "fscr_nav",
                lButton: "left_scroll",
                rButton: "right_scroll",
                oList: "fscr_ul",
                showSum: 2,
                showmun: 1,
                direction: "left"
            });
            /*关闭选项时再打开一个选项卡*/
            function SelectTab(obj) {
                //alert("prev");
                var creatpageid = obj.attr("pageid");
                //fscr_ul li显示隐藏
                $("#fscr_ul>li.menuon").removeClass("menuon");
                obj.addClass("menuon");
                //iframe显示隐藏
                $("#iframewrap iframe.show").removeClass("show").addClass("hide");
                $("#iframewrap iframe[pageid='" + creatpageid + "']").removeClass("hide").addClass("show");
            }

            /*移除选项卡和IFRAME*/
            function RemoveTab(obj) {
                var iframe_i = $("#iframewrap > iframe[pageid=" + obj.attr("pageid") + "]");
                obj.remove();
                iframe_i.remove();
                //RowScroll.moveMaxWidth = (RowScroll.moveMaxWidth-RowScroll.moveWidth);
                RowScroll.iListSum -= 1;
                RowScroll.Arrowshow();
            }

            /*删除选项卡objdelx当前选项卡的关闭按钮对象*/
            function DelectEvent(objdelx) {

                var objprev = objdelx.prev('.tabli');
                var objnext = objdelx.next('.tabli');
                if (objprev.length != 0) {
                    SelectTab(objprev);

                } else if (objnext.length != 0) {
                    SelectTab(objnext);
                } else {
                    $("#fscr_ul>li:first").addClass('menuon'); //显示首页
                    $("#ifmamedefault").removeClass("hide").addClass("show"); //显示首页ifmame
                }
                if (objdelx.text() != '首页') {
                    RemoveTab(objdelx); //是不是第一个
                };
            }

            /*刷新另外的选项卡*/
            function RefreshOtherpage(creatpageid) {
                var pageObj = $("#iframewrap iframe[pageid=" + creatpageid + "]")
                pageObj.attr('src', pageObj.attr('src'));
                return;
            }
            function CreatTabEvent(creatpageid, creaturl, creattext) {
                var fram_wrapperObj = $("#iframewrap");
                var fscr_ulObj = $("#fscr_ul");
                //BreadObj.text(creattext);//设置当前位置
                if (creaturl == null) return;
                var winH = $(window).height();//第一次加载页面时

                var iframe_i = fram_wrapperObj.children("iframe[pageid=" + creatpageid + "]")
                fram_wrapperObj.children("iframe.show").removeClass("show").addClass("hide");

                if (fram_wrapperObj.children("iframe[pageid=" + creatpageid + "]").length > 0) {

                    var carousel_li = $("#fscr_ul > li[pageid=" + creatpageid + "]");
                    fscr_ulObj.find('li').removeClass("menuon");
                    carousel_li.addClass("menuon");
                    iframe_i.removeClass("hide").addClass("show");
                    var currliLift = carousel_li.position().left;
                    var carouselLift = fscr_ulObj.position().left;
                    var carinnerW = $('#fscr_nav').width();

                    //当前选项卡保证在可显示区域
                    if (Math.abs(carouselLift) + 25 > currliLift) {
                        fscr_ulObj.css('left', -(currliLift) + 'px')
                    } else if (Math.abs(carouselLift) + carinnerW - 25 < currliLift) {
                        fscr_ulObj.css("left", carinnerW - (currliLift + carousel_li.width() + 1) + "px");
                    }
                } else {

                    $("#fscr_ul>li.menuon").removeClass("menuon");
                    $("#fscr_ul").append("<li class='tabli menuon' pageid='" + creatpageid + "'><a>" + creattext + "</a><span class='delx'></span></li>");
                    //增加li删除事件
                    $("#fscr_ul > li.tabli").off();
                    $("#fscr_ul > li.tabli").on("click", ".delx", function (e) {

                        DelectEvent($(this).parent("li.tabli"));
                        //冒泡
                        return false;
                    });
                    /*右边滑动条LI点击切换*/
                    $("#fscr_ul > li").click(function () {
                        if ($(this).hasClass('menuon')) {
                            return;
                        } else {
                            $("#fscr_ul>li").removeClass('menuon');
                            $(this).addClass('menuon');
                            var creatpageid = $(this).attr("pageid");
                            $("#iframewrap iframe.show").removeClass("show").addClass("hide");
                            $("#iframewrap iframe[pageid='" + creatpageid + "']").removeClass("hide").addClass("show");
                        }
                    });

                    RowScroll.iListSum += 1;
                    RowScroll.Arrowshow();//自动左右滑动箭头

                    var oIframe = "<iframe class='show' width='100%' height='" + (winH - 109) + "'"
                        + "pageid='" + creatpageid + "' frameborder='0'"
                        + "scrolling-x='no' src='" + creaturl + "'></iframe>";

                    fram_wrapperObj.append(oIframe);

                }
            }	
            FlashPay.Util.Ajax({
                url: '/Home/GetMenu',
                type: 'POST',
                data: null,
                success: function (response) {
                    if (response.success) {
                        var evalText = doT.template($("#menuTemplate").text());
                        var menuHtml = evalText(response)
                        $("#side_menu").html(menuHtml);
                        //console.info(menuHtml);
                        /*左边导航*/
                        $(".side-ul>li.fir-li").hover(function () {
                            if ($(this).children("ul").size()) {
                                var oTop = $(this).offset().top;
                                var oH = $(this).children("ul").height();
                                var oVisH = $(document).height();
                                var oDocH = oTop + oH;
                                if (oDocH > oVisH) {
                                    $(this).children("ul").css({ "bottom": "0px", "top": "auto" });
                                } else {
                                    $(this).children("ul").css({ "bottom": "auto", "top": "0px" });
                                }
                                $(this).children("ul").show();
                            }
                        }, function () {
                            $(this).children("ul").hide();
                        });

                        $(".sec-ul").hover(function () {
                            $(this).prev("a").addClass("active");
                        }, function () {
                            $(this).prev("a").removeClass("active");
                        });

                        $(".side-ul li").click(function () {
                            $(this).addClass("active").siblings().removeClass("active");
                        });

                        $(".sec-ul li").click(function () {
                            $(this).parent().parent().addClass("active").siblings(".side-ul li").removeClass("active");
                        });

                        /*左边菜单显示隐藏*/
                        var navobj = $("#side_menu");
                        var AObj = $("#side_ul > li > a");
                        var popObj = $("#side_ul li");
                        var fram_wrapperObj = $("#iframewrap");
                        var winH = $(window).height();//第一次加载页面时

                        NavHauto();
                        $(window).resize(function () {
                            NavHauto();
                        });

                        function NavHauto() {
                            var winH = $(window).height();
                            var fram_showObj = fram_wrapperObj.children("iframe");
                            fram_wrapperObj.height(winH - 106);//右边Iframe
                            fram_showObj.height(winH - 106);//右边Iframe
                            navobj.height(winH - 70);//左边导航
                        }


                        /*左边菜单点击加载页面*/
                        popObj.find('a').click(function () {
                            //点击加载页面
                            var creatpageid = $(this).attr("pageid");
                            var targetpage = $(this).attr("targetpage");
                            var currenttxt = $(this).text();
                            CreatTabEvent(creatpageid, targetpage, currenttxt);
                        });
                        /*右边滑动条LI(首页)点击切换*/
                        $("#fscr_ul > li:first").click(function () {
                            if ($(this).hasClass('menuon')) {
                                return;
                            } else {
                                $("#fscr_ul>li").removeClass('menuon');
                                $(this).addClass('menuon');
                                $("#iframewrap iframe.show").removeClass("show").addClass("hide");
                                $("#ifmamedefault").removeClass("hide").addClass("show");
                            }
                        });	
                        
                    } else {
                        FlashPay.UI.Tip_warning("操作失败！" + response.errorMessage);
                    }
                },
                error: function (json) {
                    FlashPay.UI.Tip_warning("操作失败！请查看网络，请重试。");
                }
            });

            var username = $.cookie('username');
            var companyname = $.cookie('companyname');
            var token = $.cookie('token');
            if (FlashPay.Util.isNullOrEmptySpance(username) || FlashPay.Util.isNullOrEmptySpance(companyname) || FlashPay.Util.isNullOrEmptySpance(token)) {
                window.location.href = "/login.html"
            }
            $("a#logout").click(function () {
                $.cookie('username', '', {
                    expires: -1
                });
                $.cookie('companyname', '', {
                    expires: -1
                });
                $.cookie('token', '', {
                    expires: -1
                });
                window.location.href = "/login.html"
            });
        });

        function Tip_success(word) {
            FlashPay.UI.Tip_success(word);
        }

        function login() {
            setTimeout(function () {
                $.cookie('username', '', {
                    expires: -1
                });
                $.cookie('companyname', '', {
                    expires: -1
                });
                $.cookie('token', '', {
                    expires: -1
                });
                window.location.href = "/login.html"
            }, 1000);
        }
    </script>
</body>
</html>